import wx
import logging
import sys
from PIL import Image


logging.basicConfig(
    format='%(asctime)s : %(levelname)s: %(message)s',
    level=logging.DEBUG)


class MainFrame(wx.Frame):
    def __init__(self, title=''):
        wx.Frame.__init__(
            self, None, id=wx.ID_ANY, title=title, pos=wx.DefaultPosition, size=wx.DefaultSize,
            style=wx.BORDER_SIMPLE | wx.TRANSPARENT_WINDOW, name=wx.FrameNameStr)

        self.SetBackgroundColour(wx.Colour(0, 200, 0))
        self.SetTransparent(150)

        filename = sys.argv[1]

        self.image = Image.open(filename)
        logging.debug(self.image.size)
        self.SetSize([i+100 for i in self.image.size])
        pic = wx.Image(filename).ConvertToBitmap()

        self.panel = wx.Panel(self, size=self.image.size)

        sb = wx.StaticBitmap(self.panel, bitmap=pic)
        tc = wx.TextCtrl(self.panel, value='hello world')
 
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(sb) 
        sizer.Add(tc) 

        self.panel.SetSizer(sizer)
        sb.Bind(wx.EVT_MOTION, self.onMove)
        sb.Bind(wx.EVT_LEFT_DOWN, self.onMove)

    def onMove(self, e):
        if e.GetEventType() == wx.wxEVT_LEFT_DOWN:
            self.prevMousePos = e.GetPosition()
        if e.Dragging():
            mousePos = e.GetPosition()
            dPos = mousePos - self.prevMousePos
            pos = self.panel.GetPosition()
            self.panel.SetPosition(pos + dPos)
            

if __name__ == '__main__':
    if len(sys.argv) > 1:
        app = wx.App()
        frame = MainFrame(title='SViewer')
        frame.Show(True)
        app.MainLoop()
